import 'package:flutter/material.dart';

class IconText extends StatefulWidget{
  final IconData icon; //图标
  final Color iconColors; //图标颜色
  final double iconFontSize; //图标颜色
  final String text;  //文字
  final Color textColors; //文字颜色
  final bool showBadge;
  final String badgeNum;  //数量
  final double height;  //高度
  final GestureTapCallback? onTap;
  final EdgeInsetsGeometry? padding;

  const IconText({
    super.key,
    required this.icon,
    required this.text,
    this.iconColors=Colors.black,
    this.textColors = Colors.black,
    this.iconFontSize = 24,
    this.showBadge=false,
    this.badgeNum = "0",
    this.height = 2, this.onTap,this.padding
  });

  @override
  State<StatefulWidget> createState() => _IconText();
}

class _IconText extends State<IconText>{
  @override
  Widget build(BuildContext context) {
    return  GestureDetector(
      onTap: widget.onTap,
      behavior: HitTestBehavior.translucent,
      child: Container(
        padding:  widget.padding ?? const EdgeInsets.fromLTRB(2, 1, 2, 1),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            widget.showBadge ? Badge(
              backgroundColor: Colors.red,
              label:  Text(widget.badgeNum),
              child: Icon(widget.icon, color: widget.iconColors,size: widget.iconFontSize,),
            ) : Icon(widget.icon, color: widget.iconColors,size: widget.iconFontSize),
            SizedBox(height: widget.height,),
            Text(widget.text,style: TextStyle(color: widget.textColors,fontSize: 13),)
          ],
        ),
      ),
    );
  }

}